home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 6023 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  4.0 KB

  1. Path: keats.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Best way to store in program messages?
  5. Date: 21 Feb 1996 10:50:30 -0800
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4gfphmINNdjt@keats.ugrad.cs.ubc.ca>
  8. References: <4gckb4$77e@news.mistral.co.uk>
  9. NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
  10.  
  11. In article <4gckb4$77e@news.mistral.co.uk>,
  12. Mike Barnard <mikebarnard@mistral.co.uk> wrote:
  13. >Hi all.
  14. >
  15. >Thanks for your past help.
  16. >
  17. >My last question threw up another in my mind. How do you, the pro's
  18. >out there, store your in-program messages?
  19. >
  20. >So far I havn't written amything of any size at all. I've gotten away
  21. >with having a function to display a title in a box and used...
  22. >
  23. >char title1[]="The program title";
  24. >char title2[]="A copyright message";
  25. >
  26. >...at the start of that function then cprintf'd the line I wanted.
  27. >Same with the menu I'm working on now, but putting the menuitem
  28. >description in a structure.
  29. >
  30. >But supposing I did a text adventure? Hundreds of messages to store.
  31. >Or a long list of error messages and other inprogram messages giving
  32. >instructions to the user. I'd obviously like them to be stored out of
  33. >harms way, not taking up too much memory, but easily accessable. Would
  34. >you store them in a seperate file #included into the main file? A
  35. >seperate function holding them? It would be nice to have them all in
  36. >one place for ease of editing.
  37.  
  38. I probably would not store a text adventure's database as static declarations.
  39. The worst thing I have done along these lines was statically declaring a tree
  40. structure for a hierarchical help system. Doing it statically enabled me to
  41. knock it off quickly. Basically, each node in the tree was a structure
  42. containing a variable array of strings, as well as a pointers to child nodes
  43. next node on the same level, previous and the parent node. You can statically
  44. build a tree of arbitrary depth this way. You could build an adventure map this
  45. way if you were so inclined.
  46.  
  47. It would be better to define your own language which describes the text in a
  48. structured way, and then have your program parse this language  and build
  49. dynamic data structures.
  50.  
  51. The UNIX-based LPMud software allows players to dynamically extend the Mud
  52. world at run-time by writing code in an interpreted language called LPC, which
  53. superficially resembles C. A module of the world is coded into an LPC file
  54. which determines the behavior of that little section of the Mud.
  55.  
  56. This is a lot more interesting than static text, since the world is constantly
  57. evolving even as you play the game.
  58.  
  59. >Also I'm not sure what memory is used by char arrays as opposed to
  60. >mallocing (something I havn't touched - yet). I've heard of the heap,
  61. >near and far memory, data and code segments... huh? As an extra
  62. >question can you point me to a good FAQ/Tutorial on heaps, near and
  63. >far etc?
  64.  
  65. The comp.lang.c FAQ does touch on dynamic memory allocation with malloc() and
  66. friends, but I wouldn't say that it serves as a tutorial. Things like "near and
  67. far" are best forgotten until you learn about data structures and program
  68. design (in a language independent fashion). Get book from the library about
  69. data structures and program design, perhaps one that uses examples from the C
  70. language. A copy of "The C Programming Language" by Kernighan and Ritchie is
  71. also a very useful companion, and will probably serve you as such for years.
  72.  
  73. I recently snagged a book called ``Fundamental Structures of Computer Science''
  74. by William A. Wulf, Mary Shaw,  Paul N. Hilfinger, and Lawrence Flon.
  75. (ISBN 0-201-08824-X) for $0.99 at a discard sale held by a university library.
  76. It's a neat paperback jam-packed with the stuff of undergraduate computer
  77. science. Much of it is review for me, but it's just so compact, I instantly
  78. knew that it would make a handy reference. Plus the price was right...  
  79. It teaches about finite state machines, models of control flow, abstract data
  80. types, algorithm efficiency, etc.
  81.  
  82. Such books can teach you a lot, if you are willing to invest the time.
  83. -- 
  84.  
  85.